import 'package:flutter/material.dart';
import 'package:flutterDemo/common_ui/common_style.dart';
import 'package:flutterDemo/pages/auth/auth_vm.dart';
import 'package:flutterDemo/route/RouteUtils.dart';
import 'package:provider/provider.dart';

class RegisterPage extends StatefulWidget {
  const RegisterPage({super.key});

  @override
  State createState() {
    return _RegisterPageState();
  }
}

class _RegisterPageState extends State<RegisterPage> {
  AuthViewModel viewModel = AuthViewModel();

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
        create: (context) {
          return viewModel;
        },
        child: Scaffold(
            backgroundColor: Colors.teal,
            body: Container(
                padding: const EdgeInsets.only(left: 20, right: 20),
                alignment: Alignment.center,
                child: Consumer<AuthViewModel>(
                  builder: (context, vm, child) {
                    return Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        commonInput(
                            labelText: "请输入账号",
                            onChanged: (value) {
                              vm.registerInfo.name = value;
                            }),
                        const SizedBox(height: 20),
                        commonInput(
                            labelText: "请输入密码",
                            obscureText: true,
                            onChanged: (value) {
                              vm.registerInfo.password = value;
                            }),
                        const SizedBox(height: 20),
                        commonInput(
                            labelText: "再次输入密码",
                            obscureText: true,
                            onChanged: (value) {
                              vm.registerInfo.rePassword = value;
                            }),
                        const SizedBox(
                          height: 50,
                        ),
                        //按钮
                        whiteBorderButton(
                            title: "点我注册",
                            onTap: () {
                              viewModel.register().then((value) {
                                if (value == true) {
                                  // showToast("注册成功");
                                  RouteUtils.pop(context);
                                }
                              });
                            })
                      ],
                    );
                  },
                ))));
  }
}
